import store from "@/store";
/** 省市区街道 */
export function address(value){
    let address = value;
    let addressInfo = "";
    if(address) {
        let split = address.split(",");
        addressInfo += split[0];
        // 街道
        if(split[1]) {
            addressInfo += `<br/>${split[1]}`
        }
    }
    return addressInfo;
}

/** 停车场类型 */
export function parkingType(value){
    const data = store.state.config.parking_type_json[value];
    if(data) { return data.label; }
}

/** 年检 */
export function yearCheckType(value){
    const data = store.state.config.year_check;
    const filterData = data.filter(item => item.value === value);
    if(filterData.length > 0) {
        return filterData[0].label
    }
    return "";
}

/** 能源类型 */
export function energyType(value){
    const data = store.state.config.energyType;
    const filterData = data.filter(item => item.value === parseInt(value)); //=== 结果值是否一致以及值类型，== 结果值是否一致
    if(filterData.length > 0) {
        return filterData[0].label
    }
    return "";
}

// 时间格式化
export function formartDate(params) {
    const date = new Date(params.value);
    const year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
    const hours = date.getHours();
    const min = date.getMinutes();
    let sec = date.getSeconds() + 1;
    month = month < 10 ? "0" + month : month;
    day = day < 10 ? "0" + day : day;
    sec = sec < 10 ? "0" + sec : sec;
    if(params.type === "date") {
        return `${year}-${month}-${day}`
    }
    if(params.type === "time") {
        return `${year}-${month}-${day} ${hours}:${min}:${sec}`
    }
}